package cn.hpclub.server.controller.admin;

import cn.hpclub.server.bean.SystemConfig;
import cn.hpclub.server.model.CmccOrder;
import cn.hpclub.server.service.AccountService;
import cn.hpclub.server.service.CmccOrderGcgmService;
import cn.hpclub.server.service.CmccOrderService;
import cn.hpclub.server.service.garrison.GarrisonService;
import cn.hpclub.server.service.promotion.PromotionService;
import cn.hpclub.server.util.ExcelLargeDataUtils;
import cn.hpclub.server.util.ExcelRenderUtil;
import cn.hpclub.server.util.InterfaceUtil;
import cn.hpclub.server.util.SystemConfigUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.JFinal;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;

public class GcgmOrderController extends BaseAdminController<CmccOrder>{



    public void list(){
        int defaultOrgId = initOrgTreeWithDefaultName();
        ConcurrentHashMap<String, String> searchInfo = getSearchInfo();

        if(!searchInfo.containsKey("org_id") || "-1".equals(searchInfo.get("org_id"))){
            searchInfo.put("org_id", InterfaceUtil.getOrgId() + "");
        }
        if(!searchInfo.containsKey("start_time") && !searchInfo.containsKey("end_time")){

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String endDate = sdf.format(new java.util.Date());
            Calendar c = Calendar.getInstance();
            try {
                c.setTime(sdf.parse(endDate));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            c.add(Calendar.MONTH, -1); // 得到前一个月
            String startDate = sdf.format(c.getTime());
            String createDate = startDate + "|" + endDate;
            searchInfo.put("start_time", startDate);
            searchInfo.put("end_time", endDate);
        }

        setAttrs(searchInfo);
        findByPageForSearch("SELECT *  ",
                new CmccOrderGcgmService().service.getSqlExceptSelect(searchInfo));
        render("/admin/cmcc_order_gcgm_list.tpl");
    }



    public void exportAll(){
        ConcurrentHashMap<String, String> searchInfo = getSearchInfo();
        if(!searchInfo.containsKey("org_id") || "-1".equals(searchInfo.get("org_id"))){
            searchInfo.put("org_id", InterfaceUtil.getOrgId() + "");
        }
        SXSSFWorkbook workbook = new CmccOrderGcgmService().service.getExcel(searchInfo);
        render(new ExcelRenderUtil(workbook, "国长国漫"));
    }




}
